iT邦幫忙

0

[Python] Datetime 處理

  • 分享至 

  • xImage
  •  

定義變數為特定時間

t = datetime.datetime(2015, 1, 12, 23, 9, 12, 946118)

時間區間迭代

for single_date in (start_date + timedelta(n) for n in range(day_count)):
    print ...

"月"加減


def monthdelta(d1, d2):
    delta = 0
    while True:
        mdays = monthrange(d1.year, d1.month)[1]
        d1 += timedelta(days=mdays)
        if d1 <= d2:
            delta += 1
        else:
            break
    return delta
   
def monthadd(sourcedate,months):
     month = sourcedate.month - 1 + months
     year = sourcedate.year + month // 12
     month = month % 12 + 1
     day = min(sourcedate.day,monthrange(year,month)[1])
     return date(year,month,day)
 
    
datetime.strptime(d, "%Y%m%d%H%M%S").strftime("%Y%m%d")
from datetime import date
d0 = date(2008, 8, 18)
d1 = date(2008, 9, 26)
delta = d1 - d0
print delta.days

datetime.now() + timedelta(days=1)

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言